﻿using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using CivilRegistry.ControlledModel.Repository;

[assembly: InternalsVisibleTo("Test")]

namespace CivilRegistry.ControlledModel
{
    /// <summary>
    /// The birth certificate object.
    /// </summary>
    public partial class BirthCertificate : ICard
    {
        #region Local Fields

        /// <summary>
        /// Holds the <see cref="BirthCertificateRepository"/> instance.
        /// </summary>
        static BirthCertificateRepository repository = new BirthCertificateRepository();

        #endregion

        #region Methods

        #region CRUD Methods

        #region Finder Methods

        /// <summary>
        /// Finds the <see cref="BirthCertificate"/> by Id.
        /// </summary>
        /// <param name="id">The id of the <see cref="BirthCertificate"/>.</param>
        /// <returns>Found <see cref="BirthCertificate"/> object, null if not found.</returns>
        public static BirthCertificate FindById(int id)
        {
            return repository.FindBy(birthCertificate => birthCertificate.BirthCertificateId == id);
        }

        /// <summary>
        /// Finds the <see cref="BirthCertificate"/> by <see cref="Person"/>.
        /// </summary>
        /// <param name="person">The <see cref="Person"/> object.</param>
        /// <returns>Found <see cref="BirthCertificate"/> object, null if not found.</returns>
        public static BirthCertificate FindByPerson(Person person)
        {
            return repository.FindBy(birthCertificate => birthCertificate.Person == person);
        }

        /// <summary>
        /// Finds the <see cref="BirthCertificate"/> by <see cref="BirthReport"/>.
        /// </summary>
        /// <param name="birthReport">The <see cref="BirthReport"/> object.</param>
        /// <returns>Found <see cref="BirthCertificate"/> object, null if not found.</returns>
        public static BirthCertificate FindByBirthReport(BirthReport birthReport)
        {
            return repository.FindBy(birthCertificate => birthCertificate.BirthReport == birthReport);
        }

        /// <summary>
        /// Finds all <see cref="BirthCertificate"/>s.
        /// </summary>
        /// <returns>Found <see cref="BirthCertificate"/> objects, empty if none are found.</returns>
        internal static List<BirthCertificate> FindAll()
        {
            return repository.FindAll();
        }

        /// <summary>
        /// Finds all <see cref="BirthCertificate"/>s.
        /// </summary>
        /// <param name="predicate">The predicate.</param>
        /// <returns>Found <see cref="BirthCertificate"/> objects, empty if none are found.</returns>
        internal static List<BirthCertificate> FindAll(Func<BirthCertificate, bool> predicate)
        {
            return repository.FindAll(predicate);
        }

        /// <summary>
        /// Retrives <see cref="BirthCertificate"/>s by provided conditions.
        /// </summary>
        /// <param name="approved">Approved flag.</param>
        /// <param name="deactivated">Deactivated flag.</param>
        /// <returns>Found <see cref="BirthCertificate"/> objects, empty if none are found.</returns>
        internal static List<BirthCertificate> GetRecordsBy(bool approved, bool deactivated)
        {
            return repository.GetRecordsBy(approved, deactivated, predicate => true);
        }

        /// <summary>
        /// Retrives <see cref="BirthCertificate"/>s by provided conditions.
        /// </summary>
        /// <param name="approved">Approved flag.</param>
        /// <param name="deactivated">Deactivated flag.</param>
        /// <param name="predicate">The predicate.</param>
        /// <returns>Found <see cref="BirthCertificate"/> objects, empty if none are found.</returns>
        internal static List<BirthCertificate> GetRecordsBy(bool approved, bool deactivated, Func<BirthCertificate, bool> predicate)
        {
            return repository.GetRecordsBy(approved, deactivated, predicate);
        }

        /// <summary>
        /// Retrives the deactive <see cref="BirthCertificate"/>s.
        /// </summary>
        /// <returns>The deactive <see cref="BirthCertificate"/>s.</returns>
        internal static List<BirthCertificate> GetDeactiveRecords()
        {
            return repository.GetDeactiveRecords(predicate => true);
        }

        /// <summary>
        /// Retrives the deactive <see cref="BirthCertificate"/>s by provided condition.
        /// </summary>
        /// <param name="predicate">The predicate.</param>
        /// <returns>The deactive <see cref="BirthCertificate"/>s.</returns>
        internal static List<BirthCertificate> GetDeactiveRecords(Func<BirthCertificate, bool> predicate)
        {
            return repository.GetDeactiveRecords(predicate);
        }

        /// <summary>
        /// Retrives the approved <see cref="BirthCertificate"/>s.
        /// </summary>
        /// <returns>The approved <see cref="BirthCertificate"/>s.</returns>
        internal static List<BirthCertificate> GetApprovedRecords()
        {
            return repository.GetApprovedRecords(predicate => true);
        }

        /// <summary>
        /// Retrives the approved <see cref="BirthCertificate"/>s by provided condition.
        /// </summary>
        /// <param name="predicate">The predicate.</param>
        /// <returns>The approved <see cref="BirthCertificate"/>s.</returns>
        internal static List<BirthCertificate> GetApprovedRecords(Func<BirthCertificate, bool> predicate)
        {
            return repository.GetApprovedRecords(predicate);
        }

        /// <summary>
        /// Retrives the non-approved <see cref="BirthCertificate"/>s.
        /// </summary>
        /// <returns>The non-approved <see cref="BirthCertificate"/>s.</returns>
        internal static List<BirthCertificate> GetNonApprovedRecords()
        {
            return repository.GetNonApprovedRecords(predicate => true);
        }

        /// <summary>
        /// Retrives the non-approved <see cref="BirthCertificate"/>s by provided condition.
        /// </summary>
        /// <param name="predicate">The predicate.</param>
        /// <returns>The non-approved <see cref="BirthCertificate"/>s.</returns>
        internal static List<BirthCertificate> GetNonApprovedRecords(Func<BirthCertificate, bool> predicate)
        {
            return repository.GetNonApprovedRecords(predicate);
        }

        #endregion

        #region CUD Methods

        /// <summary>
        /// To save the changes made to this object.
        /// </summary>
        /// <returns>Saved <see cref="BirthCertificate"/> object.</returns>
        internal BirthCertificate SaveChanges()
        {
            return repository.Update(this);
        }

        /// <summary>
        /// To insert the <see cref="BirthCertificate"/>.
        /// </summary>
        /// <param name="birthCertificate">The <see cref="BirthCertificate"/> to insert.</param>
        /// <returns>The inserted <see cref="BirthCertificate"/> object.</returns>
        internal static BirthCertificate Insert(BirthCertificate birthCertificate)
        {
            return repository.Insert(birthCertificate);
        }

        /// <summary>
        /// To update the <see cref="BirthCertificate"/>.
        /// </summary>
        /// <param name="birthCertificate">The <see cref="BirthCertificate"/> to update.</param>
        /// <returns>The updated <see cref="BirthCertificate"/> object.</returns>
        internal static BirthCertificate Update(BirthCertificate birthCertificate)
        {
            return repository.Update(birthCertificate);
        }

        /// <summary>
        /// To delete the <see cref="BirthCertificate"/>.
        /// </summary>
        /// <param name="birthCertificate">The <see cref="BirthCertificate"/> to delete.</param>
        internal static void Delete(BirthCertificate birthCertificate)
        {
            repository.Delete(birthCertificate);
        }

        #endregion

        #endregion

        #endregion
    }
}